﻿Imports MySql.Data.MySqlClient
Public Class dDatos_Fijos
    Private Const RH As String = "tipo_sangre"
    Private Const Contextura As String = "contextura"
    Private Const TI As String = "tipo_identificacion"
    Private con As MySqlConnection
    Private comando As MySqlCommand
    Private consulta As String
    Private lector As MySqlDataAdapter
    Private lector2 As MySqlDataReader
    Private data As DataSet
    Private Codigo_Departamento As String

    ' CLASE PARA CARGAR DATOS de LA BD
    Public Sub Guardar_Codigo(ByVal value As String)
        Codigo_Departamento = value
    End Sub

    Public Function CargarMysql(ByVal tabla As String) As DataSet
        con = Conexion.open()
        Select Case tabla
            Case "Rh"
                consulta = "Select * from " & Contextura & "  where estado_contextura ='A'"
            Case "Ti"
                'consulta = "Select concat(Codigo_tipo_identificacion, '-', Nombre_tipo_identificacion)as codigo from " & TI & "  where estado_tipo_identificacion ='A'"
                consulta = "Select Codigo_tipo_identificacion, Nombre_tipo_identificacion from " & TI & "  where estado_tipo_identificacion ='A'"
            Case "Dpto"
                consulta = "Select nombre_departamento from departamentos"
            Case "Mcipio"
                consulta = "Select nombre_municipio from municipios where codigo_departamento='" & Codigo_Departamento & "'"
            Case Else
                consulta = ""
        End Select
        comando = New MySqlCommand(consulta, con)
        lector = New MySqlDataAdapter(comando)
        data = New DataSet
        lector.Fill(data)
        Conexion.Close(con)
        Return data
    End Function
    Public Function Devolver_Codigo(ByVal campo As String, ByVal tabla As String) As String
        Select Case tabla
            Case "Rh"
            Case "Ti"
            Case "Dpto"
                consulta = "Select codigo_departamento from departamentos where nombre_departamento= '" & campo & "'"
            Case "Mcipio"
                consulta = "Select codigo_municipio from municipios where nombre_municipio= '" & campo & "'"
            Case Else
        End Select

        con = Conexion.open()
        comando = New MySqlCommand(consulta, con)
        lector2 = comando.ExecuteReader
        lector2.Read()
        Return lector2.GetString(0)
        Conexion.Close(con)

    End Function
    Public Function Devolver_Nombre(ByVal campo As String, ByVal tabla As String) As String
        Select Case tabla
            Case "Rh"
            Case "Ti"
            Case "Dpto"
                consulta = "Select nombre_departamento from departamentos where codigo_departamento= '" & Mid(campo, 1, 2) & "'"
            Case "Mcipio"
                consulta = "Select nombre_municipio from municipios where codigo_municipio= '" & campo & "'"
            Case Else
                consulta = ""
        End Select
        con = Conexion.open()
        comando = New MySqlCommand(consulta, con)
        lector2 = comando.ExecuteReader
        lector2.Read()
        Return lector2.GetString(0)
        Conexion.Close(con)

    End Function
End Class